import tkinter

win = tkinter.Tk()
win.title("title")
win.geometry("800x800+600+200")

###########################################
# 复选框
def update():
    message = ""
    if hobby1.get() == True:
        message += "money\n"
    if hobby2.get() == True:
        message += "power\n"
    if hobby3.get() == True:
        message += "people\n"

    text.delete(0.0,tkinter.END)
    text.insert(tkinter.INSERT, message)

hobby1 = tkinter.BooleanVar()
hobby2 = tkinter.BooleanVar()
hobby3 = tkinter.BooleanVar()
check1 = tkinter.Checkbutton(win,text="money",
                             variable=hobby1,command=update)
check1.pack()
check2 = tkinter.Checkbutton(win,text="power",
                             variable = hobby2, command = update)
check2.pack()
check3 = tkinter.Checkbutton(win,text="people",
                             variable=hobby3, command=update)
check3.pack()

text = tkinter.Text(win,width=50,height=5)
text.pack()
############################################################
# 单选框

def update2():

    text.delete(0.0, tkinter.END)
    text.insert(tkinter.INSERT,r.get())

r = tkinter.IntVar()
radio1 = tkinter.Radiobutton(win, text="one", value=1,
                             variable = r, command=update2)
radio1.pack()
radio2 = tkinter.Radiobutton(win, text="two", value=2,
                             variable = r, command=update2)
radio2.pack()

#######################################################
# 列表框
# tkinter.SINGLE 单选
# tkinter.BROWSE 单选，可滑动选中
list_value = tkinter.StringVar()
list = tkinter.Listbox(win, selectmode=tkinter.BROWSE,
                       listvariable=list_value)
list.pack()
# 添加元素
for item in ["kobe","harden","curry"]:
    # 顺序添加
    list.insert(tkinter.END,item)
# 从头添加
list.insert(tkinter.ACTIVE,"james")
list.insert(tkinter.END,["paul","jordan"])
list.select_set(2,3) # 选中

def update3():
    # list.selection_clear(0,list.size()-1) # 取消选中
    print(list.size()) # 列表大小
    print(list.get(2)) # 从列表取值
    print(list.curselection()) # 获取当前被选中序号
    print(list.select_includes(4)) # 判断是否被选中
    print(list_value.get()) # 获取所有内容

def update4(e):
    print("-"*20)

list.bind("<Double-Button-1>",update4) # 绑定事件

# 按钮
button = tkinter.Button(win, text="click", command=update3)
button.pack()



# 删除元素



#######################################################
win.mainloop()